//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Research.DataLayer;
using System.Collections.ObjectModel;

namespace Microsoft.Research.ScientificWorkflow.TridentComposer
{
    public class ParamModelKeyedCollection : KeyedCollection<string, ActivityParameter>
    {
        /// <summary>
        /// When implemented in a derived class, extracts the key from the specified element.
        /// </summary>
        /// <param name="item">The element from which to extract the key.</param>
        /// <returns>The key for the specified element.</returns>
        protected override string GetKeyForItem(ActivityParameter item)
        {
            return ParamModelKeyedCollection.GenerateKeyFromItem(item);
        }

        /// <summary>
        /// Generates the key from item.
        /// </summary>
        /// <param name="activityParam">The activity param.</param>
        /// <returns>The key for the specified element.</returns>
        public static string GenerateKeyFromItem(ActivityParameter activityParameter)
        {
            StringBuilder keyBuilder = new StringBuilder(activityParameter.ParameterClass);
            keyBuilder.Append("_");
            keyBuilder.Append(activityParameter.Direction.ToString());
            return keyBuilder.ToString();
        }
    }
}
